home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
CC_C
/
0924.ZIP
/
BGAME
< prev
next >
Wrap
Text File
|
1988-03-09
|
24KB
|
765 lines
/* BUSINESS GAME PROGRAM
COMMAND LINE - EITHER BGAME OFILE -I (period 0 data)
OR BGAME DFILE OFILE -B(alances off) -T(est only).
A Business simulation game for between 2 and 5 players or teams.
Initialise the game (creating the Period 0 data file) by
BGAME DFIL0 -i - then
BGAME DFIL0 DFIL1 to produce the equal start position and
data entry file for Period 1.
For each period enter the new market parameters in the period
data file, and the input (area prices, area marketing, production,
r & d and plant maintenance spends) for each company, then
BGAME DFILx DFILy - to run period x and create the next data file.
Reassign stdout to a file ( >PRN ) to store output for printing.
NOTES ON THE GAME:
The industry comprises a 'home' area for each company (in which the
'home' company has a transport cost advantage), and a 'common' area
in which all companies compete equally.
Total market orders depend on prices quoted, total marketing and r & d,
and the market parameters set by the operator.
Company market share depends on relative price and marketing, r & d,
and the market parameters. Marketing and r & d spends have effect for
several periods.
For simplicity, all sales are treated as made for cash.
Company input spend (marketing, production, r & d and plant maintenance)
should not exceed cash available, but an automatic loan is available
to ensure that 10000 cash is always available. Production must be input
as spend (not volume) and must exceed 7000.
The game should run for at least 5 periods. Balance sheets for all
companies should only be printed every 2, or 4, periods. Use -b option
to suppress these.
The winner is the company with the greatest total assets at the end
of the game.
Have fun - TJMC.
*/
#include smio.h
#define MINCO 2
#define MAXCO 5
#define CLS printf ("\33[2J")
/* Global program data */
struct { unsigned
/* previous data */
cash, plant, stock, stvol, turn, rdeff, loss,
md2[1 + MAXCO], md1[1+MAXCO],
/* current data */
price[1 + MAXCO], mark[1 + MAXCO], prod, rnd, pme,
/* derived results */
demand[1 + MAXCO], sales[1 + MAXCO], tots, totd, totm,
loan, pcost, pvol, cgs, trs, dep, lint, floss,
atrn[1 + MAXCO], fplant, ohds, tax;
float pfc, pvc; int grop, agp[1 + MAXCO],
netp, anp[1 + MAXCO], profit, totass;
} cd[MAXCO], *cdp;
float pp[5], atof(), pscale();
unsigned totdmd, admd[1 + MAXCO],
totsls, asls[1 + MAXCO],
totmkt, amkt[1 + MAXCO];
char name[85], ind[85];
int prd, coys, pn = sizeof (pp) / sizeof (float);
/* Initial equal start data */
#define IPBASE 40
#define IMBASE 25
#define IPROD 9050
#define IRND 200
#define IPME 120
#define ICASH 11500
#define IPLANT 6000
#define ISTOCK 1650
#define ISTVOL 50
#define ITURN 10000
#define IRDEFF 500
#define ITLOSS 100
int IMTRS [MAXCO] = { 12, 5, 4, 3, 2 };
int IPTRS [MAXCO] = { 0, 1, 2, 1, 2 };
/* Standard data input/output file texts */
char *text1 = "\nBusiness Game Data.\n",
*text2 = "\nGame title (40 chars): ",
*text3 = "\nIndustry descriptor: ",
*text3a = "\nNumber of companies: ",
*text4 = "\nNext period number: ",
*text5 = "\nCompany Data ",
*text5a = "\n ",
*text6 = "\n\nGame parameters (75 - 200, 100 nominal):\n",
*text13 =
"\n\nCompany Input: Prices (0 or > 30), Marketing ( > 0), ",
*text14 =
"\n Prod ( > 7000), R & D ( < 2000), PME ( < 2000):",
*text15 = "\n\nCompany ",
*text5b = "\n ",
*text16 = "\n\nEnd marker: ",
*ptext[] = { "\nTotal demand: ", "\nMarket effect: ",
"\nPrice effect: ", "\nR & D effect: ",
"\nProdn base: " };
/* Main program - handle files */
main (argc, argv) char *argv[];
{ static int i, j, k, bflag = 0, iflag = 0, tflag = 0;
static FILE *df, *of; FILE * fopen();
static char c, *p, s[45], *dfil = NULL, *ofil = NULL;
/* Read command line */
while (--argc)
{ if (**++argv == '-')
{ p = *argv; while (c = toupper (*++p))
{ if (c == 'B') bflag = 1;
if (c == 'T') tflag = 1;
if (c == 'I') iflag = 1; } }
else if (dfil == NULL) dfil = *argv;
else ofil = *argv; }
if (iflag == 0) /* normal run */
{ if (dfil == NULL)
{ printf ("\nNo data file specified.\n"); return; }
if ((df = fopen (dfil, "r")) == NULL)
{ printf ("\nCannot open data file %s\n", dfil); return; }
k = getdata (df); fclose (df);
switch (k)
{ case 1: printf ("\nData format error.\n"); return;
case 2: p = "Parameter"; goto exr;
case 4: p = "Price"; goto exr;
case 5: p = "Marketing"; goto exr;
case 6: p = "Production"; goto exr;
case 7: p = "R & D"; goto exr;
case 8: p = "Plant mtce";
exr : printf ("\n%s out of range.\n", p); return;
case 9: printf ("\nSpend exceeds cash.\n"); return; }
setdemand ();
for (i = 0; i < coys; ++i) coyresults (i);
for (j = totdmd = totsls = totmkt = 0; j <= coys; ++j)
{ for (i = admd[j] = asls[j] = amkt[j] = 0, cdp = cd;
i < coys; ++i, ++cdp)
{ admd[j] += cdp->demand[j];
asls[j] += cdp->sales[j];
amkt[j] += cdp->mark[j]; }
totdmd += admd[j];
totsls += asls[j];
totmkt += amkt[j]; }
if (!tflag) for (i = 0; i < coys; ++i) coyprint (i, bflag);
else { summary (); return; }
}
else /* initialisation run */
{ CLS;
printf ("\nEnter Game title (40 chars): "); gets (name);
printf ("\nEnter Industry descriptor: "); gets (ind);
do { printf ("\nEnter Number of Companies: ");
scanf ("%d", &coys); }
while (coys < MINCO || coys > MAXCO);
for (i = 0; i < pn; ++i) pp[i] = 100.;
ofil = dfil; }
if (ofil == NULL)
{ printf ("\n\nNo output file specified.\n"); return; }
if ((of = fopen (ofil, "w")) == NULL)
{ printf ("\n\nCannot open output file %s\n", ofil); return; }
outdata (of, iflag);
if (fclose (of) == -1)
printf ("\n\nCannot close output file %s\n", ofil);
} /* End of main */
/* Input the data file in standard format */
getdata (df) FILE *df;
{ static int i, j, k, tm; static char c, s[45]; static float f;
fscanf (df, text1); fscanf (df, text2);
c = getc (df);
while (c == ' ' || c == '\t') c = getc (df);
for (i = 0; i < 40; ++i)
{ if (c == '\r' || c == '\n') break;
name[i] = c; c = getc (df); }
while (c != '\r' && c != '\n') c = getc (df);
fscanf (df, text3); fscanf (df, "%s", ind);
fscanf (df, text3a); fscanf (df, "%d", &coys);
fscanf (df, text4); fscanf (df, "%d", &prd);
for (i = 0, cdp = cd; i < coys; ++i, ++cdp)
{ fscanf (df, text5); fscanf (df, "%d:", &j);
if (i != --j) return 1;
fscanf (df, "%d,%d,%d,%d,%d,%d,%d",
&(cdp->cash), &(cdp->plant), &(cdp->stock),
&(cdp->stvol), &(cdp->turn), &(cdp->rdeff), &(cdp->loss));
for (j = 0; j <= coys; ++j)
fscanf (df, ",%d", &(cdp->md2[j]));
for (j = 0; j <= coys; ++j)
fscanf (df, ",%d", &(cdp->md1[j])); }
fscanf (df, text6);
for (i = 0; i < pn; ++i)
{ fscanf (df, ptext[i]); fscanf (df, "%30s", s);
if ((f = pp[i] = atof(s)) < 74.99 || f > 200.01) return 2; }
fscanf (df, text13); fscanf (df, text14);
for (i = 0, cdp = cd; i < coys; ++i, ++cdp)
{ fscanf (df, text15); fscanf (df, "%d:", &j);
if (i != --j) return 1;
tm = 0;
for (j = 0; j <= coys; ++j)
{ fscanf (df, "%d,", &(cdp->price[j]));
k = cdp->price[j];
if (k && (k < 30 || k > 499)) return 4; }
for (j = 0; j <= coys; ++j)
{ fscanf (df, "%d,", &(cdp->mark[j]));
tm += (k = cdp->mark[j]);
if (k < 0) return 5; }
fscanf (df, "%d,%d,%d",
&(cdp->prod), &(cdp->rnd), &(cdp->pme));
if (cdp->prod < 7000) return 6;
if (cdp->rnd < 0 || cdp->rnd > 2000 ) return 7;
if (cdp->pme < 0 || cdp->pme > 2000 ) return 8;
k = tm + cdp->prod + cdp->rnd + cdp->pme;
if (k > 10000 && k > cdp->cash) return 9; }
fscanf (df, text16); k = fscanf (df, "%x", &j);
return (k == 0 || j != -1) ? 1 : 0;
} /* End of getdata */
/* Evaluate area/company demand */
setdemand ()
{ static float s, x, dd, mm, tr, tp, tm, nc, pm, aft,
mef[MAXCO], aff[MAXCO], rde[MAXCO], rdf[MAXCO];
static int i, j, k;
for (i = 0, cdp = cd, tr = 0.; i < coys; ++i, ++cdp)
{ tr += (rde[i] = ((float) cdp->rdeff * .6 + (float) cdp->rnd));
if ((x = (float) cdp->turn) < 4000.) x = 4000.;
rdf[i] = 1. + 3. * rde[i] / x; }
for (j = 0; j <= coys; ++j)
{ pm = 1000.; tp = tm = 1.; nc = 0.;
for (i = 0, cdp = cd; i < coys; ++i, ++cdp)
{ mef[i] = (((float) cdp->md2[j] + (float) cdp->md1[j]) / 2.
+ (float) cdp->mark[j]) / 2.;
tp += (float) (k = cdp->price[j]); tm += mef[i];
x = (float) k + 200. / (1. + mef[i]);
if (k) nc += 1.; if (k && x < pm) pm = x; }
s = 3. * (15. + nc) * (mm = (j < coys) ? 1.0 : 2.125);
if (tm < (125. * mm)) x = tm / (125. * mm);
else x = 3. - (250. * mm) / tm;
dd = .44 * s * pp[0] * (1. + tr/50000.) * x / pm;
if (nc > 0) { tp /= nc; tm /= nc; }
for (i = 0, cdp = cd, aft = 0.; i < coys; ++i, ++cdp)
{ x = cdp->price[j] ?
(rdf[i] * (mef[i] / tm - pscale (pp[1], .00, .15)) *
(tp / (float) cdp->price[j] -
pscale (pp[2], .76, .85))) : 0.;
aft += (aff[i] = (x > 0.) ? x : 0.); }
for (i = 0, cdp = cd; i < coys; ++i, ++cdp)
cdp->demand[j] = (aft > 0.) ? (int) (dd * aff[i] / aft) : 0;
}
} /* End of setdemand */
/* Evaluate company results and set output values */
coyresults (i)
{ static float x, y, pdf; static int j, k, as, tg, tn;
cdp = cd + i;
x = (float) cdp->rdeff * .6 + (float) cdp->rnd;
pdf = 1. - pscale (pp[3], .50, .65) * x /100000.;
if (pdf < .93) pdf = .93;
cdp->rdeff = (int) x;
cdp->pfc = 2. * ((float) cdp->plant / 20.) +
pdf * (x = pscale (pp[4], 27., 37.)) * 50.;
cdp->pvc = pdf * x - 2.;
cdp->pvol = ((float) cdp->prod - cdp->pfc) / cdp->pvc;
if (((float) cdp->pvol * cdp->pvc + cdp->pfc)
> cdp->prod) --(cdp->pvol);
cdp->pcost = (float) cdp->pvol * cdp->pvc + cdp->pfc;
as = cdp->pvol + cdp->stvol;
for (j = cdp->totd = cdp->totm = 0; j <= coys; ++j)
{ cdp->totd += cdp->demand[j];
cdp->totm += cdp->mark[j];
cdp->md2[j] = cdp->md1[j];
cdp->md1[j] = cdp->mark[j]; }
if ((x = (float) as / (float) cdp->totd) > 1.) x = 1.;
for (j = k = 0; j <= coys; ++j)
k += (cdp->sales[j] = (float) cdp->demand[j] * x);
if (k > as) cdp->sales[coys] -= (k - as);
if (as < cdp->totd && k < as) cdp->sales[coys] += (as - k);
for (j = cdp->tots = 0; j <= coys; ++j)
cdp->tots += cdp->sales[j];
for (j = cdp->trs = cdp->turn = 0; j <= coys; ++j)
{ cdp->turn += (cdp->atrn[j] = cdp->sales[j] * cdp->price[j]);
if (j == i) k = 0;
else if (j == coys) k = 1;
else k = 2;
cdp->trs += (cdp->sales[j] * k); }
if (cdp->tots <= cdp->stvol)
cdp->cgs = (float) cdp->tots *
(float) cdp->stock / (float) cdp->stvol;
else
cdp->cgs = (float) cdp->stock +
(float) (cdp->tots - cdp->stvol) *
(float) cdp->pcost / (float) cdp->pvol;
cdp->stock += (cdp->pcost - cdp->cgs);
cdp->stvol += (cdp->pvol - cdp->tots);
cdp->dep = cdp->plant / 50;
k = cdp->totm + cdp->pcost + cdp->rnd + cdp->pme;
cdp->loan = (k > cdp->cash) ? (k - cdp->cash) : 0;
cdp->lint = cdp->loan / 25;
cdp->grop = cdp->turn - cdp->cgs - cdp->trs;
cdp->ohds = cdp->rnd + cdp->lint + cdp->dep;
cdp->netp = k = cdp->grop - cdp->totm - cdp->ohds;
cdp->floss = cdp->loss; cdp->fplant = cdp->plant;
cdp->tax = (k < (int) cdp->loss) ? 0 : (k - cdp->loss) / 2;
cdp->loss = (k < (int) cdp->loss) ? cdp->loss - k : 0;
cdp->profit = k - cdp->tax;
x = (float) cdp->cgs / (float) cdp->tots;
y = (float) cdp->ohds / (float) cdp->tots;
for (j = tg = tn = 0; j <= coys; ++j)
{ if (j == i) k = 0;
else if (j == coys) k = 1;
else k = 2;
tg += (cdp->agp[j] = (float) cdp->sales[j] *
((float) cdp->price[j] - x - (float) k));
tn += (cdp->anp[j] = (float) cdp->agp[j]
- (float) cdp->mark[j]
- (float) cdp->sales[j] * y); }
if (tg != cdp->grop) cdp->agp[coys] += (cdp->grop - tg);
if (tn != cdp->netp) cdp->anp[coys] += (cdp->netp - tn);
cdp->plant += (cdp->pme - cdp->dep);
cdp->cash += (cdp->turn - cdp->pcost - cdp->totm - cdp->rnd -
cdp->pme - cdp->trs - cdp->tax);
cdp->totass = cdp->plant + cdp->stock + cdp->cash;
} /* End of coyresults */
/* Display company results */
coyprint (c, bs)
{ static int i, j, k, gp; static float x;
printf ("\n%-42.30s", name);
printf ("INDUSTRY %c COMPANY %d PERIOD %2d\n",
*ind, c + 1, prd);
printf ("\nINDUSTRY MARKET INFORMATION:");
printf ("\n\n ");
for (j = MAXCO; j > coys; --j) printf (" ");
for (j = 0; j <= coys; ++j) printf ("Area %d ", j + 1);
printf ("Total");
printf ("\nPRICES:");
for (i = 0, cdp = cd; i < coys; ++i, ++cdp)
{ printf ("\nCompany %d: ", i + 1);
for (j = MAXCO; j > coys; --j) printf (" ");
for (j = 0; j <= coys; ++j)
printf ("%6d ", cdp->price[j]); }
printf ("\n");
cdp = cd + c;
linrep ("\nOrders (000's)", admd, totdmd);
linrep ("\nSales ", asls, totsls);
linrep ("\nMarketing ", amkt, totmkt);
printf ("\n\nCOMPANY MARKET INFORMATION:\n");
linrep ("\nOrders (000's)", cdp->demand, cdp->totd);
linrep ("\nSales ", cdp->sales, cdp->tots);
linrep ("\nTurnover ", cdp->atrn, cdp->turn);
linrep ("\nMarketing ", cdp->mark, cdp->totm);
linrep ("\nGross profit ", cdp->agp, cdp->grop);
linrep ("\nNet profit ", cdp->anp, cdp->netp);
printf ("\n");
printf ("\nPROFIT & LOSS STATEMENT: ");
printf (" PRODUCTION REPORT:\n");
printf ("\nTurnover (000's) %8d", cdp->turn);
printf (" Quantity Cost Unit");
printf ("\nLess: ");
printf (" (000's) (000's)");
printf ("\nCost of goods sold %8d", -cdp->cgs);
printf (" If 10%% under %5d%8d%8.2f",
k = cdp->pvol - cdp->pvol / 10,
(int) (x = (float) k * cdp->pvc + cdp->pfc),
x / (float) k);
printf ("\nTransport costs %8d", -cdp->trs);
printf (" Current production%5d%8d%8.2f",
cdp->pvol, cdp->pcost,
(float) cdp->pcost / (float) cdp->pvol);
printf ("\n ------");
k = cdp->pvol + cdp->pvol / 10;
if (k > (cdp->fplant / 20)) k = cdp->fplant / 20;
printf (" If 10%% over %5d%8d%8.2f",
k,
(int) (x = (float) k * cdp->pvc + cdp->pfc),
x / (float) k);
printf ("\nGross profit %8d", gp = cdp->grop);
printf (" At new capacity %5d%8d%8.2f",
k = cdp->plant / 20,
(int) (x = (float) k * cdp->pvc + cdp->pfc),
x / (float) k);
printf ("\nLess: ");
printf (" Closing stock %5d%8d%8.2f",
cdp->stvol, cdp->stock,
(float) cdp->stock / (float) cdp->stvol);
printf ("\nMarketing costs %8d", -cdp->totm);
printf ("\nResearch & dev %8d", -cdp->rnd);
printf ("\nDepreciation %8d", -cdp->dep);
printf (" STATEMENT OF ASSETS:");
printf ("\nInterest (on %5d)%8d", cdp->loan, -cdp->lint);
printf ("\n ------");
printf (" Plant (000's) %8d", cdp->plant);
printf ("\nNet profit %8d", cdp->netp);
printf (" Stock %8d", cdp->stock);
printf ("\nTax (loss b/f %5d)%8d", cdp->floss, -cdp->tax);
printf (" Cash %8d", cdp->cash);
printf ("\n ------");
printf (" ------");
printf ("\nProfit %8d", cdp->profit);
printf (" Total assets %8d", cdp->totass);
printf ("\n ======");
printf (" ======");
printf ("\n");
if (!bs)
{ printf ("\nPUBLISHED ASSETS: ");
for (i = 0; i < coys; ++i)
printf (" Coy %d ", i + 1);
printf ("\n");
printf ("\nPlant (000's) ");
for (i = 0, cdp = cd; i < coys; ++i, ++cdp)
printf ("%10d", cdp->plant);
printf ("\nStock ");
for (i = 0, cdp = cd; i < coys; ++i, ++cdp)
printf ("%10d", cdp->stock);
printf ("\nCash ");
for (i = 0, cdp = cd; i < coys; ++i, ++cdp)
printf ("%10d", cdp->cash);
printf ("\n ");
for (i = 0; i < coys; ++i) printf (" ------");
printf ("\nTotal assets ");
for (i = 0, cdp = cd; i < coys; ++i, ++cdp)
printf ("%10d", cdp->totass);
printf ("\n ");
for (i = 0; i < coys; ++i) printf (" ======");
printf ("\n"); }
else printf ("\n\n\n\n\n\n\n\n\n");
printf ("\n\n\n"); /* SPACERS - REPORT IS 54 LINES */
} /* End of coyprint */
/* Print area analysis line */
linrep (ss, aa, tt) char *ss; unsigned aa[], tt;
{ static int j;
printf (ss);
for (j = MAXCO; j > coys; --j) printf (" ");
for (j = 0; j <= coys; ++j) printf ("%6d ", aa[j]);
printf ("%6d", tt); }
/* Print area/company demand */
summary()
{ static int i, j, tt;
printf ("\nCONFIDENTIAL - OPERATOR SUMMARY.");
printf ("\nMARKETING: ");
for (i = MINCO; i < coys; ++i) printf (" ");
printf ("TOTAL PRICES:");
for (i = 0, cdp = cd; i < coys; ++i, ++cdp)
{ printf ("\nC %d:", i + 1);
for (j = 0; j <= coys; ++j)
printf ("%6d", cdp->mark[j]);
printf ("%6d", cdp->totm);
printf (" ");
for (j = 0; j <= coys; ++j)
printf ("%4d", cdp->price[j]); }
printf ("\n");
printf ("\nDEMAND: ");
for (i = MINCO; i < coys; ++i) printf (" ");
printf ("TOTAL SALES PROD STOCK");
for (i = 0, cdp = cd; i < coys; ++i, ++cdp)
{ printf ("\nC %d:", i + 1);
for (j = tt = 0; j <= coys; ++j)
printf ("%6d", cdp->demand[j]);
printf ("%6d", cdp->totd);
printf ("%7d", cdp->tots);
printf ("%7d", cdp->pvol);
printf ("%7d", cdp->stvol); }
printf ("\n --------------------------------");
for (i = MINCO; i < coys; ++i) printf ("------");
printf ("\n ");
for (j = 0; j <= coys; ++j)
printf ("%6d", admd[j]);
printf ("%6d", totdmd);
printf ("%7d", totsls);
printf ("\n");
printf ("\nNET PROFIT: ");
for (i = MINCO; i < coys; ++i) printf (" ");
printf ("TOTAL PLANT STOCK CASH TOTAL");
for (i = 0, cdp = cd; i < coys; ++i, ++cdp)
{ printf ("\nC %d:", i + 1);
for (j = tt = 0; j <= coys; ++j)
printf ("%6d", cdp->anp[j]);
printf ("%6d", cdp->netp);
printf ("%7d", cdp->plant);
printf ("%7d", cdp->stock);
printf ("%7d", cdp->cash);
printf ("%7d", cdp->plant + cdp->stock +
cdp->cash); }
printf ("\n");
} /* End of prdem */
/* Scale parameters from nominal 75 - 200 range */
float pscale (p, x, y) float p, x, y;
{ return x + (p - 75.) / 125. * (y - x); }
/* Output the next data template in standard format */
outdata (of, ff) FILE *of;
{ static int i, j, k; static char c, s[40];
fprintf (of, "%s", text1);
fprintf (of, "%s%-40s", text2, name);
fprintf (of, "%s%c", text3, *ind);
fprintf (of, "%s%d", text3a, coys);
fprintf (of, "%s%d\n", text4,
ff ? 0 : prd + 1);
for (i = 0, cdp = cd; i < coys; ++i, ++cdp)
{ fprintf (of, "%s%d:", text5, i + 1);
fprintf (of, " %d, %d, %d, %d, %d, %d, %d,",
ff ? ICASH : cdp->cash,
ff ? IPLANT : cdp->plant,
ff ? ISTOCK : cdp->stock,
ff ? ISTVOL : cdp->stvol,
ff ? ITURN : cdp->turn,
ff ? IRDEFF : cdp->rdeff,
ff ? ITLOSS : cdp->loss);
fprintf (of, "%s", text5a);
for (j = 0; j < coys; ++j)
fprintf (of, "%d, ",
ff ? IMBASE * IMTRS [(5 * coys + i - j) % coys]
: cdp->md2[j]);
fprintf (of, "%d, ",
ff ? IMBASE * IMTRS [0] : cdp->md2[coys]);
fprintf (of, "%s", text5a);
for (j = 0; j < coys; ++j)
fprintf (of, "%d, ",
ff ? IMBASE * IMTRS [(5 * coys + i - j) % coys]
: cdp->md1[j]);
fprintf (of, "%d",
ff ? IMBASE * IMTRS [0] : cdp->md1[coys]); }
fprintf (of, "%s", text6);
for (i = 0; i < pn; ++i)
{ fprintf (of, "%s", ptext[i]);
fprintf (of, "%8.1f", pp[i]); }
fprintf (of, "%s", text13); fprintf (of, "%s", text14);
for (i = 0; i < coys; ++i)
{ fprintf (of, "%s%d: ", text15, i + 1);
if (ff)
{ for (j = 0; j < coys; ++j)
fprintf (of, "%d, ", IPBASE +
IPTRS [(5 * coys - i + j) % coys]);
fprintf (of, "%d, ", IPBASE + 1);
fprintf (of, "%s", text5b);
for (j = 0; j < coys; ++j)
fprintf (of, "%d, ", IMBASE *
IMTRS [(5 * coys + i - j) % coys]);
fprintf (of, "%d, ", IMBASE * IMTRS [0]);
fprintf (of, "%s", text5b);
fprintf (of, "%d, ", IPROD);
fprintf (of, "%d, ", IRND);
fprintf (of, "%d ", IPME); }
else fprintf (of, "\n\n"); }
fprintf (of, "%s%s", text16, "FFFF\n\n");
} /* End of outdata */
#list-
/* SCANF/FSCANF/SSCANF FUNCTIONS - 16 BIT INPUT ONLY */
scanf (fs) int *fs;
{ int getc(), ungetc(); return _ffin (stdin, fs, getc, ungetc); }
fscanf (fs) int *fs;
{ int getc(), ungetc(); return _ffin(*fs, --fs, getc, ungetc); }
sscanf (fs) int *fs;
{ int _mgt(), _mungt(); return _ffin(fs, --fs, _mgt, _mungt); }
_ffin (fp, pp, read, ungetc)
char *fp, **pp; int (*read)(), (*ungetc)();
{ static int bb, base, value, asflag, sflag,
ch, temp, i, count, width;
static char *ff, c; int _ffgd();
ff = *pp--; count = 0;
while (c = *ff++)
{ if (isspace (c)) continue;
if (c != '%')
{ while (isspace (ch = (*read) (fp)));
if (ch == c) continue;
else return (ch == EOF) ? EOF : count; }
sflag = asflag = 0;
if ((*ff) == '*') { ++asflag; ++ff; }
width = isdigit (*ff) ? 0 : -1;
if (width == 0)
{ while ((c = *ff) >= '0' && c <= '9')
{ width = width * 10 + (c - '0'); ++ff; } }
switch ( toupper (c = *ff++))
{ case 'D':
case 'U': base = 10; goto decode;
case 'O': base = 8; goto decode;
case 'X': base = 16;
decode:
bb = 0; while (isspace (ch = (*read) (fp)));
if (ch == EOF) return EOF;
if (width && (ch == '+' || ch == '-'))
{ if (ch == '-') ++sflag;
ch = (*read) (fp); --width; }
if (width && base == 16 && ch == '0')
{ temp = (*read) (fp); --width;
if (toupper (temp) == 'X' && width)
{ ch = (*read) (fp); --width; }
else
{ (*ungetc) (temp, fp); ++width; } }
if ((value = _ffgd(ch, base)) == -1) return count;
while (width && (value != -1))
{ bb = bb * base + value;
ch = (*read) (fp); --width;
value = _ffgd (ch, base); }
(*ungetc) (ch, fp);
if (sflag) bb = - bb;
if (!asflag) { * (int *) (*pp) = bb; ++count; --pp; }
break;
case 'S':
while (isspace (ch = (*read) (fp)));
if (ch == EOF) return EOF;
while (width && ch != ' ' && ch != '\t' && ch != '\r'
&& ch != '\n' && ch != EOF)
{ if (!asflag) *(*pp)++ = ch;
ch = (*read) (fp); --width; }
(*ungetc) (ch, fp);
if (!asflag)
{ *(*pp) = '\0'; ++count; --pp; }
break;
case 'C':
if ((ch = (*read) (fp)) == EOF) return EOF;
else if (!asflag) { *(*pp) = ch; ++count; --pp; }
break;
default: return count;
} }
return count;
} /* End of _ffin */
/* Utilities for scanf and sscanf */
_ffgd (ch, base)
{ if (ch >= '0' && ch <= '9') ch -= '0';
else if (isalpha (ch = toupper (ch))) ch -= ('A' - 10);
else return -1;
return (ch < base) ? ch : -1; }
_mgt (s) char **s; { return (*(*s) != '\0') ? *(*s)++ : EOF; }
_mungt (c, s) int c; char **s; { --(*s); return c; }
#include ?smfps.lib?
#include ?smio.lib?